import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
// import Home from '../views/Home.vue'
// import About from '../views/About.vue'

// 路由懒加载：利用import函数的分包特性，打包后不会打入主包app.js中，这样首次加载时会更快，需要使用该页面时再加载
const Home = () => import(/*webpackChunkName:'home'*/'../views/Home.vue')
const About = () => import(/*webpackChunkName:'about'*/'../views/About.vue')
const User = () => import(/*webpackChunkName:'user'*/'../views/User.vue')

// 创建一个路由
const router = createRouter({
  // 指定采用的模式:hash
  // history: createWebHashHistory(),
  // history模式
  history: createWebHistory(),
  // 映射关系
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: Home,
      meta: {
        name: 'zhangsan',
        age: 18
      }
    },
    {
      path: '/about',
      name: 'about',
      component: About
    },
    {
      path: '/user/:id',
      name: 'user',
      component: User
    },
    {
      path: '/:pathMatch(.*)*',
      component: () => import('../views/NotFound.vue')
    }
  ],

})

export default router